package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "C端-购物车接口")
@Slf4j
public class ShoppingCartController
{
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 往购物车添加商品按钮
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping ("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        log.info("看看参数:{}" ,shoppingCartDTO);
        log.info("添加购物车...");

        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping ("/list")
    public Result<List<ShoppingCart>> list()
    {
        log.info("查询购物车...");
       List <ShoppingCart> list =shoppingCartService.list();
        return Result.success(list);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result clean()
    {
        log.info("清空购物车...");
        shoppingCartService.clean();
        return Result.success();
    }
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO)
    {
        log.info("删除购物车中的一个商品...");
        shoppingCartService.sub(shoppingCartDTO);
//        shoppingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }
}
